package com.gorkr;

import java.util.ArrayList;
import java.util.List;

/**
 * @author gorkr
 * @title: O05
 * @projectName my-leetcode
 * @description: 替换空格
 * @date 2021/12/1622:51
 */

// String 有 chartAt方法啊！！！
public class O05 {
    public String replaceSpace(String s) {
        List space = new ArrayList<Integer>();
        int start = 0;
        int end = 0;
        String result = "";
        char[] c = s.toCharArray();
        for (int i = 0; i < c.length; i++) {
            if(c[i]==' '){
                end=i;
                result+=s.substring(start,end)+"%20";
                start=i+1;
            }
        }
        if(start==0){
            return s;
        }
        if((end+1)<=(s.length()-1)){
            result+=s.substring(end+1);
        }




        return result;


    }

}
